#pragma once

#include "Protocol.h"

#include <string>

#include <vector>
#include <stack>

#include <fstream>
#include <sstream>

#include "TcpClient.h"

namespace libdmail
{
    struct MailInfo
    {
        int mNum;
        int mSize;
        string mUidl;
    };

    enum POP3Status {POP3WELCOME, POP3USER, POP3PASS, STAT, LIST, UIDL, RETR, POP3QUIT, END};


    class POP3: public Protocol
    {
    private:
        TcpClient *mTcpClient;

        string mPOP3Server;

        string mPOP3Port;

        int mPOP3Status;

        vector<MailInfo> mMailInfoVector;
        int mMailInfoCurrentIndex;
        int mMailInfoCurrentSize;

        stack<MailInfo> mMailTnfoToGetStack;

    private:
        string mPOP3User;
        string mPOP3Pass;

    private:
         ofstream myPOP3Mbox;
 
    public:
        POP3(void);
    public:
        ~POP3(void);
    
        int connectPOP3Server(string pop3Server, string pop3Port, string user, string pass);

    public:
        int virtual onDataReceived(stringstream *str, int strLen);
        int virtual sendData(string data);

        int requestUSER();
        int requestPASS();
        int requestSTAT();
        int requestLIST();
        int requestUIDL();
        int requestRETR(int num);
        int requestQUIT();

        int response(stringstream *strStrm, int strLen);
        int responseGREET(stringstream *strStrm, int strLen);
        int responseUSER(stringstream *strStrm, int strLen);
        int responsePASS(stringstream *strStrm, int strLen);
        int responseSTAT(stringstream *strStrm, int strLen);
        int responseLIST(stringstream *strStrm, int strLen);
        int responseUIDL(stringstream *strStrm, int strLen);
        int responseRETR(stringstream *strStrm, int strLen);
        int responseQUIT(stringstream *strStrm, int strLen);

    };
}